App.require(["canvasTool"], function (canvasTool) {
    function Marker(parent) {
        this.parent = parent;
        this.markers = [];
        this.markerObj = {};
    }
    Marker.prototype = {
        constructor: Marker,
        add: function (id) {
            if (this.markers.indexOf(id) === -1) this.markers.push(id);
        },
        getUseById: function (id) {
            return this.markerObj[id];
        },
        createMarkerByStr: function (str, target, ratio) {
            ration = ratio || 1;
            if (!str) return null;
            if (str.indexOf("#") == 0) {
                str = str.slice(1);
                if (this.markers.indexOf(str) !== -1) {
                    var component = this.parent.getComponentById(str);
                    if (component) {
                        if (this.markerObj[str]) {
                            if (this.markerObj[str].indexOf(target) === -1) this.markerObj[str].push(target);
                        }
                        else this.markerObj[str] = [target];
                        return component;
                    }
                }
            }
            return null;
        },
        reset: function (id) {
            this.markerObj[id] = null;
        },
        remove: function (value, target) {
            var list = this.markerObj[value];
            if (list) {
                var index = list.indexOf(target);
                if (index !== -1) list.splice(index, 1);
            }
        },
        destroy: function () {
            this.parent = null;
            this.markers.length = 0;
            this.markers = null;
            this.markerObj = null;
        }
    };

    App.define("marker", {
        marker: Marker
    })
})